package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemSelfTeamAchieveBinding;
import com.sgb.kjwl.model.entity.self.SelfTeamAchieveEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MDateUtil;

import java.util.List;

public class  SelfTeamAchieveAdapter extends BaseRecycleAdapter<SelfTeamAchieveEntity> {

    private IRecyclerItemClick itemClick;

    public SelfTeamAchieveAdapter(Context context, List<SelfTeamAchieveEntity> data) {
        super(context, R.layout.item_self_team_achieve, data);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamAchieveEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ((ItemSelfTeamAchieveBinding) holder.getmBinding()).btnDelete.setOnClickListener(view -> {
            if (itemClick != null) {
                itemClick.delete(entity);
            }
        });
        ((ItemSelfTeamAchieveBinding) holder.getmBinding()).btnEdit.setOnClickListener(view -> {
            if (itemClick != null) {
                itemClick.edit(entity);
            }
        });
        holder.getmBinding().getRoot().setOnClickListener(view -> {
            if (itemClick != null) {
                itemClick.onItemClick(entity);
            }
        });
    }

    public void setItemClick(IRecyclerItemClick itemClick) {
        this.itemClick = itemClick;
    }

    public interface IRecyclerItemClick {
        void delete(SelfTeamAchieveEntity entity);

        void edit(SelfTeamAchieveEntity entity);

        void onItemClick(SelfTeamAchieveEntity entity);
    }

    @BindingAdapter(value = {"startTime", "endTime"}, requireAll = false)
    public static void bindStartEndDate(TextView textView, Long startTime, Long endTime) {
        textView.setText(MDateUtil.getStartAndEndDate(startTime, endTime));
    }
}
